<?php
	session_start();
	require_once 'config.php';
	require_once 'com/UserLogin.php';
	
	$sesija = 0;
	if(isset($_SESSION['user_log']) && !empty($_SESSION['user_log'])){
		$sesija = 1;
	}else{ $sesija = 0; }
	
	$prijava = 0;
	
	if(isset($_POST['prijava'])){
		if(isset($_POST['username']) && isset($_POST['u_pass'])){
			$authentication = new UserLogin($_POST['username'], $_POST['u_pass']);
			if($authentication->Authentication()){
				$prijava = 1;
				$_SESSION['user_log'] = $authentication->getUserName();
			}
		}
	}
	
	$auth = $sesija | $prijava;
	
?>
<html>
	<head>
		<title>Project1</title>
	</head>
	<body style="margin: 0px;">
		<div style="margin: 10px; padding: 20px; background:silver;">
		<?php if($auth == 0){  ?>
			<form action="<?php print $_SERVER['PHP_SELF']; ?>" method="post">
				<table cellspacing="2px" cellpadding="10px">
					<tr>
						<td>User Name:</td>
						<td><input type="text" name="username" id="username"/></td>
					</tr>
					<tr>
						<td>Password:</td>
						<td><input type="password" name="u_pass" id="u_pass"/></td>
					</tr>
					<tr>
						<td collspan="2">
							<input type="submit" name="prijava" id="prijava" value="Prijava" />
						</td>
					</tr>
				</table>
			</form>
		<?php }else{ 
			if(isset($_SESSION['user_log'])){
				print "Dobro dosao <b>" . $_SESSION['user_log'] . "</b>";
			}	
		} ?>
		</div>
		<div style="padding: 10px; background-color: buttonface;"> UserName: <b>admin</b><br/> Password: <b>admin</b> </div>
	</body>
</html>